inspector: Add a minimal Data tab
authorMatthias Clasen <mclasen@redhat.com>
Sat, 10 May 2014 04:50:21 +0000 (00:50 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 11 May 2014 02:04:33 +0000 (22:04 -0400)
This will eventually show useful information about the content
of tree models.

modules/inspector/Makefile.am
modules/inspector/data-list.c [new file with mode: 0644]
modules/inspector/data-list.h [new file with mode: 0644]
modules/inspector/data-list.ui [new file with mode: 0644]
modules/inspector/inspector.gresource.xml
modules/inspector/module.c
modules/inspector/window.c
modules/inspector/window.h
modules/inspector/window.ui

index 2ab2bb5f2cccb4570028d9e182a43117852f01ee..e673bfc7997d9c538d7002761f890de932b240e4 100644 (file)
@@ -42,7 +42,9 @@ libgtkinspector_la_SOURCES = \
        themes.h \
        themes.c \
        signals-list.h \
-       signals-list.c
+       signals-list.c \
+       data-list.h \
+       data-list.c
 
 libgtkinspector_la_CPPFLAGS = \
        -I$(top_srcdir)                 \
diff --git a/modules/inspector/data-list.c b/modules/inspector/data-list.c
new file mode 100644 (file)
index 0000000..9ccc86d
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2014 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include <glib/gi18n-lib.h>
+#include "data-list.h"
+
+enum
+{
+  COLUMN_NUMBER,
+  COLUMN_TYPE
+};
+
+struct _GtkInspectorDataListPrivate
+{
+  GtkListStore *model;
+  GtkTreeViewColumn *number_column;
+  GtkCellRenderer *number_renderer;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorDataList, gtk_inspector_data_list, GTK_TYPE_BOX)
+
+static void
+render_number (GtkTreeViewColumn *column,
+               GtkCellRenderer   *renderer,
+               GtkTreeModel      *model,
+               GtkTreeIter       *iter,
+               gpointer           data)
+{
+  gint number;
+  gchar text[100];
+
+  gtk_tree_model_get (model, iter, COLUMN_NUMBER, &number, -1);
+  g_snprintf (text, 100, "%d", number);
+  g_object_set (renderer, "text", text, NULL);
+}
+
+static void
+gtk_inspector_data_list_init (GtkInspectorDataList *sl)
+{
+  sl->priv = gtk_inspector_data_list_get_instance_private (sl);
+  gtk_widget_init_template (GTK_WIDGET (sl));
+  gtk_tree_view_column_set_cell_data_func (sl->priv->number_column,
+                                           sl->priv->number_renderer,
+                                           render_number,
+                                           NULL, NULL);
+}
+
+void
+gtk_inspector_data_list_set_object (GtkInspectorDataList *sl,
+                                    GObject              *object)
+{
+  GtkTreeIter iter;
+  gint i;
+
+  gtk_list_store_clear (sl->priv->model);
+
+  if (!GTK_IS_TREE_MODEL (object))
+    {
+      gtk_widget_hide (GTK_WIDGET (sl));
+      return;
+    }
+
+  gtk_widget_show (GTK_WIDGET (sl));
+
+  for (i = 0; i < gtk_tree_model_get_n_columns (GTK_TREE_MODEL (object)); i++)
+    {
+      GType type;
+      type = gtk_tree_model_get_column_type (GTK_TREE_MODEL (object), i);
+
+      gtk_list_store_append (sl->priv->model, &iter);
+      gtk_list_store_set (sl->priv->model, &iter,
+                          COLUMN_NUMBER, i,
+                          COLUMN_TYPE, g_type_name (type),
+                          -1);
+    }  
+}
+
+static void
+gtk_inspector_data_list_class_init (GtkInspectorDataListClass *klass)
+{
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/inspector/data-list.ui");
+  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorDataList, model);
+  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorDataList, number_column);
+  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorDataList, number_renderer);
+}
+
+GtkWidget *
+gtk_inspector_data_list_new (void)
+{
+  return GTK_WIDGET (g_object_new (GTK_TYPE_INSPECTOR_DATA_LIST, NULL));
+}
+
+// vim: set et sw=2 ts=2:
diff --git a/modules/inspector/data-list.h b/modules/inspector/data-list.h
new file mode 100644 (file)
index 0000000..c27ab99
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2014 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _GTK_INSPECTOR_DATA_LIST_H_
+#define _GTK_INSPECTOR_DATA_LIST_H_
+
+#include <gtk/gtk.h>
+
+#define GTK_TYPE_INSPECTOR_DATA_LIST            (gtk_inspector_data_list_get_type())
+#define GTK_INSPECTOR_DATA_LIST(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), GTK_TYPE_INSPECTOR_DATA_LIST, GtkInspectorDataList))
+#define GTK_INSPECTOR_DATA_LIST_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass), GTK_TYPE_INSPECTOR_DATA_LIST, GtkInspectorDataListClass))
+#define GTK_INSPECTOR_IS_DATA_LIST(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTK_TYPE_INSPECTOR_DATA_LIST))
+#define GTK_INSPECTOR_IS_DATA_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GTK_TYPE_INSPECTOR_DATA_LIST))
+#define GTK_INSPECTOR_DATA_LIST_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), GTK_TYPE_INSPECTOR_DATA_LIST, GtkInspectorDataListClass))
+
+
+typedef struct _GtkInspectorDataListPrivate GtkInspectorDataListPrivate;
+
+typedef struct _GtkInspectorDataList
+{
+  GtkBox parent;
+  GtkInspectorDataListPrivate *priv;
+} GtkInspectorDataList;
+
+typedef struct _GtkInspectorDataListClass
+{
+  GtkBoxClass parent;
+} GtkInspectorDataListClass;
+
+G_BEGIN_DECLS
+
+GType      gtk_inspector_data_list_get_type   (void);
+GtkWidget *gtk_inspector_data_list_new        (void);
+void       gtk_inspector_data_list_set_object (GtkInspectorDataList *sl,
+                                               GObject              *object);
+
+G_END_DECLS
+
+#endif // _GTK_INSPECTOR_DATA_LIST_H_
+
+// vim: set et sw=2 ts=2:
diff --git a/modules/inspector/data-list.ui b/modules/inspector/data-list.ui
new file mode 100644 (file)
index 0000000..bd2786d
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface domain="gtk30">
+  <object class="GtkListStore" id="model">
+    <columns>
+      <column type="gint"/>
+      <column type="gchararray"/>
+    </columns>
+  </object>
+  <template class="GtkInspectorDataList" parent="GtkBox">
+    <property name="orientation">vertical</property>
+    <child>
+      <object class="GtkScrolledWindow">
+        <property name="visible">True</property>
+        <property name="expand">True</property>
+        <property name="hscrollbar-policy">automatic</property>
+        <property name="vscrollbar-policy">always</property>
+        <property name="shadow-type">in</property>
+        <child>
+          <object class= "GtkTreeView">
+            <property name="visible">True</property>
+            <property name="model">model</property>
+            <child>
+              <object class="GtkTreeViewColumn" id="number_column">
+                <property name="title" translatable="yes">Column</property>
+                <child>
+                  <object class="GtkCellRendererText" id="number_renderer">
+                    <property name="scale">0.8</property>
+                  </object>
+                  <attributes>
+                    <attribute name="text">0</attribute>
+                  </attributes>
+                </child>
+              </object>
+            </child>
+            <child>
+              <object class="GtkTreeViewColumn">
+                <property name="title" translatable="yes">Type</property>
+                <child>
+                  <object class="GtkCellRendererText">
+                    <property name="scale">0.8</property>
+                  </object>
+                  <attributes>
+                    <attribute name="text">1</attribute>
+                  </attributes>
+                </child>
+              </object>
+            </child>  
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
index 0feec7c97d5bf4a29184f70028dfb1929bf5526e..752d2cdac5cf1dbe37770fe562275537063c0b30 100644 (file)
@@ -10,5 +10,6 @@
     <file>themes.ui</file>
     <file>window.ui</file>
     <file>signals-list.ui</file>
+    <file>data-list.ui</file>
   </gresource>
 </gresources>
index 31b4a1cb02f80c2181dbe4a1f8f8b02888868941..0e7a25fb3316588464f48e297c20c7f52033adf0 100644 (file)
@@ -25,6 +25,7 @@
 #include "button-path.h"
 #include "classes-list.h"
 #include "css-editor.h"
+#include "data-list.h"
 #include "object-hierarchy.h"
 #include "property-cell-renderer.h"
 #include "prop-list.h"
@@ -56,6 +57,7 @@ gtk_module_init (gint *argc, gchar ***argv)
   g_type_ensure (GTK_TYPE_INSPECTOR_PROPERTY_CELL_RENDERER);
   g_type_ensure (GTK_TYPE_INSPECTOR_WINDOW);
   g_type_ensure (GTK_TYPE_INSPECTOR_SIGNALS_LIST);
+  g_type_ensure (GTK_TYPE_INSPECTOR_DATA_LIST);
 }
 
 
index d93d2047fb8e593aa0e274dc666c8577e60c8563..479c4e580298c220770170cbe624780e02fd148d 100644 (file)
@@ -35,6 +35,7 @@
 #include "python-hooks.h"
 #include "python-shell.h"
 #include "button-path.h"
+#include "data-list.h"
 #include "themes.h"
 #include "signals-list.h"
 
@@ -78,6 +79,7 @@ on_widget_tree_selection_changed (GtkInspectorWidgetTree *wt,
       gtk_inspector_button_path_set_object (GTK_INSPECTOR_BUTTON_PATH (iw->button_path), selected);
       gtk_inspector_classes_list_set_object (GTK_INSPECTOR_CLASSES_LIST (iw->classes_list), selected);
       gtk_inspector_css_editor_set_object (GTK_INSPECTOR_CSS_EDITOR (iw->widget_css_editor), selected);
+      gtk_inspector_data_list_set_object (GTK_INSPECTOR_DATA_LIST (iw->data_list), selected);
 
       if (GTK_IS_WIDGET (selected))
         gtk_inspector_flash_widget (iw, GTK_WIDGET (selected));
@@ -176,6 +178,7 @@ gtk_inspector_window_class_init (GtkInspectorWindowClass *klass)
   gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, object_hierarchy);
   gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, python_shell);
   gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, widget_popup);
+  gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, data_list);
 
   gtk_widget_class_bind_template_callback (widget_class, on_inspect);
   gtk_widget_class_bind_template_callback (widget_class, on_graphic_updates_toggled);
index 1e9bd699968ae0ea5e1a2f46a4aeb0b31a39a480..da2742fe42918ff4bb92cd5bdbdeaea1f560d9e8 100644 (file)
@@ -50,6 +50,7 @@ typedef struct
   GtkWidget *classes_list;
   GtkWidget *widget_css_editor;
   GtkWidget *object_hierarchy;
+  GtkWidget *data_list;
 
   GtkWidget *widget_popup;
 
index 75044c2f6732a91b7b0c05ec56ce6fa9bfaa95f1..e6f643b908998ced0ed8ba5cd9ea8f3b4d613101 100644 (file)
                         <property name="label" translatable="yes">Custom CSS</property>
                       </object>
                     </child> 
+                    <child>
+                      <object class="GtkInspectorDataList" id="data_list">
+                      </object>
+                    </child>
+                    <child type="tab">
+                      <object class="GtkLabel">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">Data</property>
+                      </object>
+                    </child> 
                   </object>
                   <packing>
                     <property name="resize">True</property>